import request from "@/utils/request";
import { getToken, getRefreshToken ,setToken} from '@/utils/auth'

// 登录并获得token
export function login(data) {
    return request.post("/token", data).then(res=>{
        console.log(res);
        setToken(res.data.AccessToken,res.data.RefreshToken);
    });
}

// 不登录的情况下刷新token
export function refreshToken() {
    let accessToken = getToken();
    let refreshToken = getRefreshToken();
    let data = {
        accessToken,
        refreshToken
    }
    console.log(data);
    if (accessToken && refreshToken) {
        return request.post("/refresh", data).then(res=>{
            console.log(res);
        });
    } else {
        return false;
    }
}